﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import net.wooga.pets.events.*;
    import __AS3__.vec.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.machines.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;
    import flash.errors.*;

    public class EntranceAreaQueManagerCommand extends Command {

        private const PET_ID_NOT_AVAILABLE:String = null;

        public var event:InfoEvent;
        public var worldModel:WorldModel;
        private var _petID:String;
        private var _entranceAreaId:String;
        private var _entranceMachineVO:EntranceMachineVO;

        override public function execute():void{
            if (this.thePetLeft_TheEntranceArea()){
                this.markThatThisPetLeft(this.petID);
            } else {
                if (this.thePetArrivedAt_TheEntranceArea()){
                    this.markThatThisPetArrived(this.petID);
                } else {
                    if (this.thePetsArrivedOnInitWorld()){
                        this.markPetsAsArrivedOnInit(IAccessible(this.worldModel.getRoomById(this.entranceAreaId)).patientIdList);
                    };
                };
            };
        }
        private function thePetLeft_TheEntranceArea():Boolean{
            return (((((this.eventHasIdProperty()) && (((this.event.info) && ((this.event.info.roomLeftFrom == this.entranceAreaId)))))) && ((this.event.type == EventConstants.ON_PATIENT_LEFT_FROM_ROOM))));
        }
        private function thePetArrivedAt_TheEntranceArea():Boolean{
            return ((this.event.type == EventConstants.ON_ARRIVAL_AT_HOSPITAL));
        }
        private function thePetsArrivedOnInitWorld():Boolean{
            return ((this.event.type == EventConstants.RENDER_ENTRANCE_AREA_PETS_ON_INIT_WORLD));
        }
        private function markThatThisPetLeft(_arg1:String):void{
            if (_arg1 == this.PET_ID_NOT_AVAILABLE){
                throw (new IllegalOperationError("Cannot remove this pet because it's id is NULL"));
            };
            this.entranceMachineVO.removePetIdFromQue(_arg1);
            this.entranceMachineVO.dispatchUpdatedPetsPositions();
        }
        private function markThatThisPetArrived(_arg1:String):void{
            if (_arg1 == this.PET_ID_NOT_AVAILABLE){
                throw (new IllegalOperationError("Cannot add this pet because it's id is NULL"));
            };
            this.entranceMachineVO.addPetIdToQue(_arg1);
            this.entranceMachineVO.dispatchUpdatedPetsPositions();
        }
        private function markPetsAsArrivedOnInit(_arg1:Vector.<String>):void{
            var _local2:String;
            for each (_local2 in _arg1) {
                this.entranceMachineVO.addPetIdToQue(_local2);
            };
            this.entranceMachineVO.dispatchUpdatedPetsPositions();
        }
        private function eventHasIdProperty():Boolean{
            return (!((this.event.id == this.PET_ID_NOT_AVAILABLE)));
        }
        private function get petID():String{
            if (this.event.id == this.PET_ID_NOT_AVAILABLE){
                return (this.PET_ID_NOT_AVAILABLE);
            };
            return ((this._petID = ((this._petID) || (IMoving((this.worldModel.getActor(this.event.id) as IMoving)).id))));
        }
        private function get entranceMachineVO():EntranceMachineVO{
            return ((this._entranceMachineVO = ((this._entranceMachineVO) || (EntranceMachineVO(IRoom(this.worldModel.getRoomById(this.entranceAreaId)).machine)))));
        }
        private function get entranceAreaId():String{
            return ((this._entranceAreaId = ((this._entranceAreaId) || (this.worldModel.getRoomIdsOfType(GameConstants.TYPE_ENTRANCE_AREA)[0]))));
        }

    }
}//package net.wooga.pets.controllers 
